package com.sieg.controller;

import com.sieg.domain.User;
import com.sieg.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@CrossOrigin
@Controller
//@RequestMapping
public class UserController {
    @Resource
    private UserService service;

    @RequestMapping("/registerUser")
    @ResponseBody
    public String addUser(User user) {
        String tips = "注册成功";
        List userList = service.registerUser(user);
        if (userList != null) {
            service.addUser(user);
            tips = "该用户名已注册";
        }
        if (service.addUser(user) == 0) {
            tips = "注册失败";
        }
        return tips;
    }

//    @RequestMapping("/loginUser")
//    @ResponseBody
//    public Object loginUser(User user, String userName, HttpServletResponse response) {
//        System.out.println(userName);
//        response.setHeader("Access-Control-Allow-Origin", "*");
//        User userMessage = service.loginUser(user);
//        if (userMessage != null) {
//            return userMessage;
//        }
//        return "账号或密码错误,请重新输入";
//    }

    @RequestMapping("/loginUser")
    public void loginUser() {
        System.out.println(1);
//        System.out.println(userName + "," + password);
    }
}
